# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
        node = ListNode(0)
        pre_node = node
        index = 0
        while l1 or l2:
            a = index
            if l1:
                a += l1.val
                l1 = l1.next
            if l2:
                a += l2.val
                l2 = l2.next
            index = a//10
            pre_node.next = ListNode(a%10)
            pre_node = pre_node.next
        if index:
            pre_node.next = ListNode(index)
        return node.next            
                
    
        